package com.xyw.code.platform.webapps.rest;


import com.xyw.code.common.core.entity.vo.Result;
import com.xyw.code.platform.common.entity.dto.DictDTO;
import com.xyw.code.platform.common.entity.po.SysDict;
import com.xyw.code.platform.webapps.service.ISysDictService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author xyw
 * @since 2020-02-07
 */
@RestController
@RequestMapping("/sysDict")
public class SysDictController {

    @Autowired
    private ISysDictService dictService;

    /**
     * 根据名称获取字典值详情
     * @param name
     * @return
     */
    @GetMapping("/queryDictDetailList")
    @ApiOperation(value = "根据名称获取字典值详情", notes = "根据名称获取字典值详情")
    public Result queryDictDetailList(@RequestParam String name) {
        return Result.success(dictService.selectDictDetailList(name));
    }


    /**
     * 获取字典列表集合
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/query")
    @ApiOperation(value = "获取字典列表集合", notes = "获取字典列表集合")
    public Result query(Integer page, Integer pageSize,String detailName,String value,String type) {
        return Result.success(dictService.selectDictList(page, pageSize,detailName,value,type));
    }

    /**
     * 保存字典信息
     *
     * @param sysDict
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "保存字典信息", notes = "保存字典信息")
    public Result add(@RequestBody SysDict sysDict) {
        return Result.success(dictService.save(sysDict));
    }

    /**
     * 更新字典
     *
     * @param dictDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新字典", notes = "更新字典")
    public Result update(@RequestBody DictDTO dictDto) {
        return Result.success(dictService.updateDict(dictDto));
    }

    /**
     * 根据id删除字典
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除字典", notes = "根据id删除字典")
    public Result delete(@PathVariable("id") String id) {
        return Result.success(dictService.deleteDict(id));
    }
}

